Learn R Programming

MXM (version 0.9.5)

Partial correlation between two variables: Partial correlation

Description

Partial correlation between two variables when a correlation matrix is given.

Usage

partialcor(R, indx, indy, indz)

Arguments

R
A correlation matrix.
indx
The index of the first variable whose conditional correlation is to estimated.
indy
The index of the second variable whose conditional correlation is to estimated.
indz
The index of the conditioning variables.

Value

A number, the partial correlation coefficient.

Details

Given a correlation matrix the function will caclulate the partial correlation between variables indx and indy conditioning on variable(s) indz.

See Also

testIndFisher, testIndSpearman, permcor, pc.con

Examples

Run this code
r <- cor( iris[, 1:4] )
partialcor(r, 1, 2, 0) 
r[1, 2]  ## the same as above

y = as.vector( iris[, 1] )
x = as.vector( iris[, 2] )
z = as.vector( iris[, 3] )
e1 = resid( lm(y ~ z) )
e2 = resid( lm(x ~ z) )
cor(e1, e2)
partialcor(r, 1,2, 3)

Run the code above in your browser using DataLab